package com.spring.rabbitmq.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.spring.rabbitmq.utils.RabbitMQUtils;
import lombok.SneakyThrows;

/**
 * @Author: lzx
 * @Data: 2021/04/27/10:47
 * @Description：
 */
public class Product {
    @SneakyThrows
    public static void main(String[] args) {
        //获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取通道对象
        Channel channel = connection.createChannel();
        //声明队列
        channel.queueDeclare("work", true, false, false, null);
        //发布消息
        for (int i = 1; i<= 20; i++) {
            channel.basicPublish("", "work", null, (i+"==> hello work queue").getBytes());
        }
        //关闭资源
        RabbitMQUtils.closeConnectionAndChannel(connection, channel);


    }
}
